/*
 * @Author: gitee_com_zb
 * @Date: 2024-12-03 14:55:56
 * @LastEditors: gitee_com_zb
 * @LastEditTime: 2024-12-03 14:56:06
 * @FilePath: /algorithm/每日一题7.字典序最小回文串(easy).cpp
 * @Description: 题目链接 https://leetcode.cn/problems/lexicographically-smallest-palindrome?envType=problem-list-v2&envId=two-pointers
 */
class Solution {
public:
    string makeSmallestPalindrome(string s) {
        // 双指针,两边同时走,遇到不同的字符取较小的值
        int left = 0, right = s.size() - 1;
        while (left < right) {
            if (s[left] != s[right])
                s[left] = s[right] = min(s[left], s[right]);
            left++, right--;
        }
        return s;
    }
};